package base;

import java.util.Arrays;
import java.util.Comparator;

class Emp implements Comparable<Emp>{
	private int id;
	private String name;
	private int age;
	private int salary;
	
	public Emp(int id, String name, int age, int salary) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the age
	 */
	public int getAge() {
		return age;
	}

	/**
	 * @param age the age to set
	 */
	public void setAge(int age) {
		this.age = age;
	}

	/**
	 * @return the salary
	 */
	public int getSalary() {
		return salary;
	}

	/**
	 * @param salary the salary to set
	 */
	public void setSalary(int salary) {
		this.salary = salary;
	}

	@Override
    public String toString() {
        return "[id=" + this.id + ", name=" + this.name + ", age=" + this.age + ", salary=" +
                this.salary + "]";
    }
	
	public int compareTo(Emp e) {
		
		int flag = this.getId() - e.getId();
        if(flag==0) flag = this.getName().compareTo(e.getName());
        if(flag==0) flag = this.getAge()-e.getAge();
        if(flag==0) flag = this.getSalary() - e.getSalary();
        return flag;
	}
	
}

class NameComparator implements Comparator<Emp>{

	public int compare(Emp o1, Emp o2) {
		return o1.getName().compareTo(o2.getName());
	}
	
}
public class Comparing {

	
	public static void main(String[] args) {
		Emp[] empArr = new Emp[4];
		empArr[0] = new Emp(10, "Mikey", 25, 10000);
		empArr[1] = new Emp(20, "Arun", 29, 20000);
		empArr[2] = new Emp(1, "Lisa", 35, 5000);
		empArr[3] = new Emp(1, "Pankaj", 32, 50000);
		//sorting employees array using Comparable interface implementation
		Arrays.sort(empArr);//,new NameComparator());
		System.out.println("Default Sorting of Employees list:\n"+Arrays.toString(empArr));
	}

}
